using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VABUAUFM
    {
        public DataRow Convert2ABUAUFM(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryABUAUFM(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["ABUMANDANT"] = " ".PadRight(2 ); 
         dwReturn["ABUAUFKRS"] = " ".PadRight(2 ); 
         dwReturn["ABUAUFLFD"] = " ".PadRight(6 ); 
         dwReturn["ABUAUFPOS"] = " ".PadRight(3 ); 
         dwReturn["ABUAPOS"] = " ".PadRight(4 ); 
         dwReturn["ABUAUPOS"] = " ".PadRight(2 ); 
         dwReturn["ABUWAKZ"] = " ".PadRight(1 ); 
         dwReturn["ABUKUNDNR"] = " ".PadRight(8 ); 
         dwReturn["ABUWERK"] = " ".PadRight(3 ); 
         dwReturn["ABUABT"] = " ".PadRight(3 ); 
         dwReturn["ABUART"] = " ".PadRight(20 ); 
         dwReturn["ABUVAR"] = " ".PadRight(3 ); 
         dwReturn["ABUBRT"] = " ".PadRight(0 ); 
         dwReturn["ABUVKAUFKRS"] = " ".PadRight(2 ); 
         dwReturn["ABUVKAUFLFD"] = " ".PadRight(6 ); 
         dwReturn["ABUVKAUFPOS"] = " ".PadRight(3 ); 
         dwReturn["ABUWDUPOS"] = " ".PadRight(2 ); 
         dwReturn["ABUFARBE"] = " ".PadRight(10 ); 
         dwReturn["ABUAUFMSL"] = " ".PadRight(2 ); 
         dwReturn["ABUFILLER"] = " ".PadRight(38 ); 
         dwReturn["ABUAENDZL"] = " ".PadRight(0 ); 
         dwReturn["ABUAENDBEN"] = " ".PadRight(8 ); 
         dwReturn["ABUAENDDAT"] = " ".PadRight(0 ); 
         dwReturn["ABUNEUBEN"] = " ".PadRight(8 ); 
         dwReturn["ABUNEUDAT"] = " ".PadRight(0 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapABUAUFM(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveABUAUFM(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryABUAUFM(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapABUAUFM(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertABUAUFM(dwLocal, ITXDBVERSION);
            }
            UpdateABUAUFM(dwLocal);
        }
        public void InsertABUAUFM(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO ABUAUFM(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryABUAUFM(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM ABUAUFM WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM ABUAUFM  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "ABUAUFM";
            Return = Result;
            return Return;
        }
        public void DeleteABUAUFM(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM ABUAUFM   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateABUAUFM(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE ABUAUFM SET "
                    +"ABUMANDANT= :ABUMANDANT,"
                    +"ABUAUFKRS= :ABUAUFKRS,"
                    +"ABUAUFLFD= :ABUAUFLFD,"
                    +"ABUAUFPOS= :ABUAUFPOS,"
                    +"ABUAPOS= :ABUAPOS,"
                    +"ABUAUPOS= :ABUAUPOS,"
                    +"ABUWAKZ= :ABUWAKZ,"
                    +"ABUKUNDNR= :ABUKUNDNR,"
                    +"ABUWERK= :ABUWERK,"
                    +"ABUABT= :ABUABT,"
                    +"ABUART= :ABUART,"
                    +"ABUVAR= :ABUVAR,"
                    +"ABUBRT= :ABUBRT,"
                    +"ABUVKAUFKRS= :ABUVKAUFKRS,"
                    +"ABUVKAUFLFD= :ABUVKAUFLFD,"
                    +"ABUVKAUFPOS= :ABUVKAUFPOS,"
                    +"ABUWDUPOS= :ABUWDUPOS,"
                    +"ABUFARBE= :ABUFARBE,"
                    +"ABUAUFMSL= :ABUAUFMSL,"
                    +"ABUFILLER= :ABUFILLER,"
                    +"ABUAENDZL= :ABUAENDZL,"
                    +"ABUAENDBEN= :ABUAENDBEN,"
                    +"ABUAENDDAT= :ABUAENDDAT,"
                    +"ABUNEUBEN= :ABUNEUBEN,"
                    +"ABUNEUDAT= :ABUNEUDAT,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("ABUMANDANT", OracleType.NVarChar).Value = dwData["ABUMANDANT"].ToString(); 
          or1.Parameters.Add("ABUAUFKRS", OracleType.NVarChar).Value = dwData["ABUAUFKRS"].ToString(); 
          or1.Parameters.Add("ABUAUFLFD", OracleType.NVarChar).Value = dwData["ABUAUFLFD"].ToString(); 
          or1.Parameters.Add("ABUAUFPOS", OracleType.NVarChar).Value = dwData["ABUAUFPOS"].ToString(); 
          or1.Parameters.Add("ABUAPOS", OracleType.NVarChar).Value = dwData["ABUAPOS"].ToString(); 
          or1.Parameters.Add("ABUAUPOS", OracleType.NVarChar).Value = dwData["ABUAUPOS"].ToString(); 
          or1.Parameters.Add("ABUWAKZ", OracleType.NVarChar).Value = dwData["ABUWAKZ"].ToString(); 
          or1.Parameters.Add("ABUKUNDNR", OracleType.NVarChar).Value = dwData["ABUKUNDNR"].ToString(); 
          or1.Parameters.Add("ABUWERK", OracleType.NVarChar).Value = dwData["ABUWERK"].ToString(); 
          or1.Parameters.Add("ABUABT", OracleType.NVarChar).Value = dwData["ABUABT"].ToString(); 
          or1.Parameters.Add("ABUART", OracleType.NVarChar).Value = dwData["ABUART"].ToString(); 
          or1.Parameters.Add("ABUVAR", OracleType.NVarChar).Value = dwData["ABUVAR"].ToString(); 
          or1.Parameters.Add("ABUBRT", OracleType.NVarChar).Value = dwData["ABUBRT"].ToString(); 
          or1.Parameters.Add("ABUVKAUFKRS", OracleType.NVarChar).Value = dwData["ABUVKAUFKRS"].ToString(); 
          or1.Parameters.Add("ABUVKAUFLFD", OracleType.NVarChar).Value = dwData["ABUVKAUFLFD"].ToString(); 
          or1.Parameters.Add("ABUVKAUFPOS", OracleType.NVarChar).Value = dwData["ABUVKAUFPOS"].ToString(); 
          or1.Parameters.Add("ABUWDUPOS", OracleType.NVarChar).Value = dwData["ABUWDUPOS"].ToString(); 
          or1.Parameters.Add("ABUFARBE", OracleType.NVarChar).Value = dwData["ABUFARBE"].ToString(); 
          or1.Parameters.Add("ABUAUFMSL", OracleType.NVarChar).Value = dwData["ABUAUFMSL"].ToString(); 
          or1.Parameters.Add("ABUFILLER", OracleType.NVarChar).Value = dwData["ABUFILLER"].ToString(); 
          or1.Parameters.Add("ABUAENDZL", OracleType.NVarChar).Value = dwData["ABUAENDZL"].ToString(); 
          or1.Parameters.Add("ABUAENDBEN", OracleType.NVarChar).Value = dwData["ABUAENDBEN"].ToString(); 
          or1.Parameters.Add("ABUAENDDAT", OracleType.NVarChar).Value = dwData["ABUAENDDAT"].ToString(); 
          or1.Parameters.Add("ABUNEUBEN", OracleType.NVarChar).Value = dwData["ABUNEUBEN"].ToString(); 
          or1.Parameters.Add("ABUNEUDAT", OracleType.NVarChar).Value = dwData["ABUNEUDAT"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
